package com.ghy.utils.File;



import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.io.File;


@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

//    public static String basePath = "E:/projectStatic";
public static String basePath = "/root/ghyProjectUpload/ghy_position/";


    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * @Description: 对文件的路径进行配置, 创建一个虚拟路径/file/** ，即只要在<img src="/file/images/20180522/9aa64b2b-a558-421e-929c-537ff0aecdba.jpg" />便可以直接引用图片
         *这是图片的物理路径 "file:/+本地图片的地址"
         * @Date： Create in 14:08 2017/12/20
         *
         */
        //读取配置文件中的上传路径
        File file = new File(basePath);
        String serverPath = file.getAbsolutePath();
        registry.addResourceHandler("/Path/**").addResourceLocations("file:" + serverPath + "/resources/static/");
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");

        //swagger3
        registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
        super.addResourceHandlers(registry);



    }


}
